#include<iostream>
#include<iomanip>
using namespace std;
class Time;
class Date {
private:
	int year, month, day;
public:
	Date();
	Date(int y, int m, int d);
	friend void display(const Date& date, const Time& time);
};
class Time {
private:
	int hour, min, s;
public:
	Time();
	Time(int a,int b,int c);
	friend void display(const Date& date, const Time& time);
};
Date::Date() {
	year = 0;
	month = 0;
	day = 0;
}
Date::Date(int y, int m, int d) {
	year = y;
	month = m;
	day = d;
}
Time::Time() {
	hour = 0;
	min = 0;
	s = 0;
}
Time::Time(int a, int b, int c) {
	hour = a;
	min = b;
	s = c;
}
void display(const Date& date, const Time& time) {
	cout << date.year << '-';
	cout << setw(2) << setfill('0') << date.month << '-';
	cout << setw(2) << setfill('0') << date.day << ' ';
	cout << setw(2) << setfill('0') << time.hour << ':';
	cout << setw(2) << setfill('0') << time.min << ':';
	cout << setw(2) << setfill('0') << time.s << endl;

}
int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		Date date(a, b, c);
		Time time(d, e, f);
		display(date, time);
	}
	return 0;
}